package com.example.demo.vo;


import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;

@Data
public class GrowthRecordVO {
    // 记录ID
    private Long id;
    // 记录日期
    private LocalDate date;
    // 身高(cm)
    private BigDecimal height;
    // 体重(kg)
    private BigDecimal weight;
    // BMI指数
    private BigDecimal bmi;
    // 评估结果
    private String evaluation;
    // 备注
    private String note;

    /**
     * 计算BMI和评估结果
     */
    public void calculateBMIAndEvaluation() {
        if (this.height == null || this.weight == null) {
            return;
        }
        
        // 将身高从cm转换为m
        BigDecimal heightInMeters = this.height.divide(new BigDecimal("100"), 2, BigDecimal.ROUND_HALF_UP);
        
        // 计算BMI
        this.bmi = this.weight.divide(heightInMeters.multiply(heightInMeters), 1, BigDecimal.ROUND_HALF_UP);
        
        // 计算评估结果
        if (bmi.compareTo(new BigDecimal("18.5")) < 0) {
            this.evaluation = "体重偏轻";
            this.note = "建议适当增加营养摄入,保持均衡饮食,适量运动增强体质。";
        } else if (bmi.compareTo(new BigDecimal("24.9")) <= 0) {
            this.evaluation = "体重正常";
            this.note = "目前体重处于健康范围,建议保持良好的饮食运动习惯。";
        } else if (bmi.compareTo(new BigDecimal("29.9")) <= 0) {
            this.evaluation = "超重";
            this.note = "建议控制饮食摄入,增加运动量,预防肥胖相关疾病。";
        } else {
            this.evaluation = "肥胖";
            this.note = "需要注意控制体重,建议咨询医生制定科学的减重计划。";
        }
    }
}